/**
 * @file order.js
 * @author swan
 */
const app = getApp()
Page({
    data: {

    },
    onLoad: function (option) {
        console.log(option);
        swan.showToast({
            title: '正在加载...',
            icon: 'loading',
            duration: 10000
        });

        let openID = getApp().getOpenID(),
            token = getApp().getToken();

        this.orderDetails(openID, token, option.id);
    },
    orderDetails(openID, token, orderNo) {
        swan.request({
            url: getApp().getUrl('/v1/order/order-details'),
            data: {
                open_id: openID,
                order_no: orderNo
            },
            header: {
                'Authorization': 'Bearer ' + token,
            },
            method: 'POST',
            success: res => {
                swan.hideToast();
                let data = res.data;
                this.setData({
                    orderDetails: data.data
                })
            },
            fail: err => {
                swan.hideToast();
                swan.showToast({
                    title: '订单详情展示失败',
                    icon: 'none'
                });
            }
        });
    },
    copy(event) {
        var secret = event.currentTarget.dataset.secret;
        swan.setClipboardData({
            data: secret,
            success: res => {
                swan.showToast({
                    title: '复制成功'
                });
            },
            fail: err => {
                swan.showToast({
                    title: '复制失败'
                });
                console.log('setClipboardData fail', err);
            }
        });
    }
});
